home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Cuadros de diálogo / DialogsWithRegistry / DialogsWithRegistry.cs next >
Encoding:
Text File  |  2002-05-23  |  2.5 KB  |  71 lines

  1. //--------------------------------------------------
  2. // DialogsWithRegistry.cs ⌐ 2001 by Charles Petzold
  3. //--------------------------------------------------
  4. using Microsoft.Win32;
  5. using System;
  6. using System.Drawing;
  7. using System.Windows.Forms;
  8.  
  9. class DialogsWithRegistry: BetterFontAndColorDialogs
  10. {
  11.      const string strRegKey = 
  12.                          "Software\\ProgrammingsWindowsWithCSharp\\DialogsWithRegistry";
  13.      const string strFontFace  = "FontFace";
  14.      const string strFontSize  = "FontSize";
  15.      const string strFontStyle = "FontStyle";
  16.      const string strForeColor = "ForeColor";
  17.      const string strBackColor = "BackColor";
  18.      const string strCustomClr = "CustomColor";
  19.  
  20.      public new static void Main()
  21.      {
  22.           Application.Run(new DialogsWithRegistry());
  23.      }
  24.      public DialogsWithRegistry()
  25.      {
  26.           Text = "Dißlogos Fuente y Color con Registro";
  27.  
  28.           RegistryKey regkey = Registry.CurrentUser.OpenSubKey(strRegKey);
  29.  
  30.           if (regkey != null)
  31.           {
  32.                Font = new Font((string) regkey.GetValue(strFontFace),
  33.                                float.Parse(
  34.                                    (string) regkey.GetValue(strFontSize)),
  35.                                (FontStyle) regkey.GetValue(strFontStyle));
  36.  
  37.                ForeColor = Color.FromArgb(
  38.                               (int) regkey.GetValue(strForeColor));
  39.  
  40.                BackColor = Color.FromArgb(
  41.                               (int) regkey.GetValue(strBackColor));
  42.  
  43.                int[] aiColors = new int[16];
  44.  
  45.                for (int i = 0; i < 16; i++)
  46.                     aiColors[i] = (int) regkey.GetValue(strCustomClr + i);
  47.  
  48.                clrdlg.CustomColors = aiColors;
  49.  
  50.                regkey.Close();
  51.           }
  52.      }
  53.      protected override void OnClosed(EventArgs ea)
  54.      {
  55.           RegistryKey regkey = 
  56.                          Registry.CurrentUser.OpenSubKey(strRegKey, true);
  57.           if (regkey == null)
  58.                regkey = Registry.CurrentUser.CreateSubKey(strRegKey);
  59.  
  60.           regkey.SetValue(strFontFace,  Font.Name);
  61.           regkey.SetValue(strFontSize,  Font.SizeInPoints.ToString());
  62.           regkey.SetValue(strFontStyle, (int) Font.Style);
  63.           regkey.SetValue(strForeColor, ForeColor.ToArgb());
  64.           regkey.SetValue(strBackColor, BackColor.ToArgb());
  65.  
  66.           for (int i = 0; i < 16; i++)
  67.                regkey.SetValue(strCustomClr + i, clrdlg.CustomColors[i]);
  68.  
  69.           regkey.Close();
  70.      }
  71. }